﻿// Copyright 2009 Mike Geise
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace Falcon.Core.Domain
{
	public class PollChoice : EntityBase<PollChoice>
	{
		/// <summary>
		/// Gets or sets the poll id.
		/// </summary>
		/// <value>The poll id.</value>
		public virtual int PollId
		{
			get; 
			set;
		}

		/// <summary>
		/// Gets or sets the title.
		/// </summary>
		/// <value>The title.</value>
		public virtual string Title
		{
			get;
			set;
		}

		/// <summary>
		/// Gets or sets the slug.
		/// </summary>
		/// <value>The slug.</value>
		public virtual string Slug
		{
			get;
			set;
		}

		/// <summary>
		/// Gets or sets the votes.
		/// </summary>
		/// <value>The votes.</value>
		public virtual int Votes
		{
			get; 
			set;
		}

		/// <summary>
		/// Gets or sets the voters.
		/// </summary>
		/// <value>The voters.</value>
		public virtual int Voters
		{
			get; 
			set;
		}

		/// <summary>
		/// Gets or sets the order.
		/// </summary>
		/// <value>The order.</value>
		public virtual int Order
		{
			get;
			set;
		}

		/// <summary>
		/// Updates the voters and voters.
		/// </summary>
		public virtual void Update()
		{
			this.UpdateVotes();
			this.UpdateVoters();
		}

		/// <summary>
		/// Updates the votes.
		/// </summary>
		public virtual void UpdateVotes()
		{
			UpdateVotes(1, true);
		}

		/// <summary>
		/// Updates the votes.
		/// </summary>
		/// <param name="value">The value.</param>
		/// <param name="addition">if set to <c>true</c> [addition].</param>
		public virtual void UpdateVotes(int value, bool addition)
		{
			if (addition)
			{
				this.Votes += value;
			}
			else
			{
				this.Votes -= value;
			}
		}

		/// <summary>
		/// Updates the voters.
		/// </summary>
		public virtual void UpdateVoters()
		{
			UpdateVoters(1, true);
		}

		/// <summary>
		/// Updates the voters.
		/// </summary>
		/// <param name="value">The value.</param>
		/// <param name="addition">if set to <c>true</c> [addition].</param>
		public virtual void UpdateVoters(int value, bool addition)
		{
			if (addition)
			{
				this.Voters += value;
			}
			else
			{
				this.Voters -= value;
			}
		}

		/// <summary>
		/// Validates this instance.
		/// </summary>
		public override void Validate()
		{
			this.Rules().Validate(this);
		}
	}
}